using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Commons.Models.Settings.Serialization
{
	[Serializable]
	public class SerializableHashSet<V> : HashSet<V>, ISerializable
	{
		public SerializableHashSet() : base()
		{
		}

		public SerializableHashSet(IEnumerable<V> collection) : base(collection)
		{
		}

		protected SerializableHashSet(SerializationInfo info, StreamingContext context)
		{
			V[] values = (V[])info.GetValue("values", typeof(V[]));
			for (int i=0; i<values.Length; i++)
				Add(values[i]);
		}

		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			V[] values = new V[this.Count];
			CopyTo(values);
			info.AddValue("values", values, typeof(V[]));
		}
	}
}